class @AdminResponseCreateView extends CustomView
    
    el: $('#content')

    initialize: ->
        super

    render: ->
        @GetTemplate(SiteMap.Admin.Responses.CreateTemplate, (compiledTemplate) =>
            $(@el).html(compiledTemplate(@model.toJSON()))

            $("#UserId").combobox({
                source: SiteMap.Admin.Shared.GetUsers
                isDynamic: true
            })
            $('#BookId').combobox({
                source: SiteMap.Admin.Shared.GetBooks
                isDynamic: true
            })
            $("#DateOfPublish").datepicker()
        )

    events:
        "click .buttons>button.save": "save"
        "click .buttons>button.cancel": "cancel"

    save: (e) ->
        e.preventDefault()
        Loading.Start()
        Messages.WriteMessage('Creating response.')

        data = $(@el).find("form.general").serialize()

        $.post(SiteMap.Admin.Responses.Create, data, (response)=>
            if (response.SuccessMessage != null && response.SuccessMessage.length > 0)
                Messages.WriteSuccessMessage(response.SuccessMessage)
                @Navigate(SiteMap.Admin.Responses.Listing, true)
            else
                Messages.WriteErrors(response.Errors)
                Loading.Stop()
        )

    cancel:(e) ->
        e.preventDefault()
        Loading.Start()
        Messages.Clear()
        @Navigate(SiteMap.Admin.Responses.Listing, true)